//引入封装好的Api
import { reqCategoryList, reqGetBannerList, reqFloortList } from '@/api'

// home模块的小仓库
// 此处state中存的数据到底是数组还是对象，别瞎写，，看服务器返回的是什么类型。
const state = {
    categoryList: [], //home仓库中存储三级菜单的数据
    bannerList: [], //轮播图数据
    floorList: [] //floor组件数据
}
const mutations = {
    CATEGORYLIST(state, categoryList) {
        state.categoryList = categoryList
        console.log(state, categoryList);
    },
    GETBANNERLIST(state, bannerList) {
        state.bannerList = bannerList
    },
    GETFLOORLIST(state, floorList) {
        state.floorList = floorList
    }

}
const actions = {
        // 通过Api里面的接口函数，向服务器发请求，获取服务器的数据。
        async categoryList({ commit }) {
            let result = await reqCategoryList()
                // console.log(result)
            if (result.code == 200) {
                commit('CATEGORYLIST', result.data)
            }
        },
        //获取首页轮播图的数据
        async getBannerList({ commit }) {
            // axios点get点post返回一个promise对象。等待他响应结果---await,,,await就要有async
            let result = await reqGetBannerList()
                // console.log(result);
            if (result.code == 200) {
                commit('GETBANNERLIST', result.data)
            }
        },
        // 获取floor数据
        async getFloorList({ commit }) {
            let result = await reqFloortList()
            if (result.code == 200) {
                commit('GETFLOORLIST', result.data)
            }
        }
    }
    // 计算属性
const getters = {}
export default {
    state,
    mutations,
    actions,
    getters,
}